package cn.iocoder.yudao.module.cms.qlink.controller.app;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.cms.qlink.bo.QlinkIdentifyBO;
import cn.iocoder.yudao.module.cms.qlink.dal.dataobject.QlinkDO;
import cn.iocoder.yudao.module.cms.qlink.service.QlinkService;
import cn.iocoder.yudao.module.cms.qlink.vo.QlinkRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 App - 快捷链接")
@RestController
@RequestMapping("/cms/qlink")
@Validated
public class AppQlinkController {

    @Resource
    private QlinkService qlinkService;

    @GetMapping("/all-identify")
    @Operation(summary = "已定义的所有标识")
    @PermitAll
    public CommonResult<List<QlinkIdentifyBO>> getAllIdentify() {
        List<QlinkIdentifyBO> allIdentify = qlinkService.getAllIdentify();
        return success(allIdentify);
    }

    @GetMapping("/list")
    @Operation(summary = "获得所有快捷链接")
    @Parameter(name = "identify", description = "位置标识：首页九宫格（home_grid）、首页轮播图（home_carousel）、首页横幅（home_banner）、个人中心顶部菜单（mine_top_menu）", required = true, example = "home_grid")
    @PermitAll
    public CommonResult<List<QlinkRespVO>> getQlinkAll(@RequestParam("identify") String identify) {
        List<QlinkDO> list = qlinkService.getQlinkAll(identify);
        return success(BeanUtils.toBean(list, QlinkRespVO.class));
    }

    @GetMapping("/top-list")
    @Operation(summary = "获得前 N 条快捷链接")
    @Parameter(name = "identify", description = "位置标识：首页九宫格（home_grid）、首页轮播图（home_carousel）、首页横幅（home_banner）、个人中心顶部菜单（mine_top_menu）", required = true, example = "home_carousel")
    @Parameter(name = "limit", description = "条数", required = true, example = "5")
    @PermitAll
    public CommonResult<List<QlinkRespVO>> getQlinkTopList(@RequestParam("identify") String identify, @RequestParam("limit") Integer limit) {
        List<QlinkDO> list = qlinkService.getQlinkTopList(identify, limit);
        return success(BeanUtils.toBean(list, QlinkRespVO.class));
    }

}
